home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / c / amiga-c / files / code.c next >
Text File  |  1999-06-14  |  3KB  |  120 lines

  1.  
  2. The code:
  3. ---------------------------------------------------------------------------
  4.  
  5. /*
  6.     true if midi data was received.
  7.     false if no midi data was received.
  8.  
  9.     other_signals contain the signal mask for received signals.
  10. */
  11. ULONG ReceiveMidiData(ULONG *other_signals)
  12. {
  13.     struct IOExtSer *ioextser = si->serialio;
  14.     register ULONG serialmask = (1L << si->msgport->mp_SigBit);
  15.     register ULONG bits;
  16.     ULONG buffered;
  17.     ULONG i;
  18.  
  19.     data_ready = 0;
  20.  
  21.     while (1)
  22.     {
  23.         GetStamp(×tamp);
  24.  
  25.         ioextser->IOSer.io_Command = SDCMD_QUERY;
  26.         ioextser->IOSer.io_Flags   = IOF_QUICK;
  27.         BeginIO((struct IORequest *)ioextser);
  28.  
  29.         if(!(ioextser->IOSer.io_Flags & IOF_QUICK))
  30.         {
  31.             bits = Wait(*other_signals | serialmask);
  32.  
  33.             GetStamp(×tamp);
  34.  
  35.             if (bits & serialmask)
  36.             {
  37.                 WaitIO((struct IORequest *)ioextser);
  38.             }
  39.             else
  40.             {
  41.                 AbortIO((struct IORequest *)ioextser);
  42.                 WaitIO((struct IORequest *)ioextser);
  43.                 *other_signals = bits & (~serialmask);
  44.                 return(data_ready);
  45.             }
  46.         }
  47.  
  48.         if ((buffered = ioextser->IOSer.io_Actual) == 0)
  49.         {
  50.             if (data_ready)
  51.             {
  52.                 *other_signals = 0L;
  53.                 return data_ready;
  54.             }
  55.  
  56.             GetStamp(×tamp);
  57.  
  58.             ioextser->IOSer.io_Command = CMD_READ;
  59.             ioextser->IOSer.io_Length  = 1;
  60.             ioextser->IOSer.io_Data    = (APTR)serialbuffer;
  61.             SendIO((struct IORequest *)ioextser);
  62.  
  63.             bits = Wait(*other_signals | serialmask);
  64.  
  65.             GetStamp(×tamp);
  66.  
  67.             if (bits & serialmask)
  68.             {
  69.                 WaitIO((struct IORequest *)ioextser);
  70.                 pb_byte = serialbuffer[0];
  71.                 (*ProcessByte)();
  72.             }
  73.             else
  74.             {
  75.                 AbortIO((struct IORequest *)ioextser);
  76.                 WaitIO((struct IORequest *)ioextser);
  77.                 *other_signals = bits & (~serialmask);
  78.                 return(data_ready);
  79.             }
  80.         }
  81.         else // bytes in queue
  82.         {
  83.             ioextser->IOSer.io_Command = CMD_READ;
  84.             ioextser->IOSer.io_Flags   = IOF_QUICK;
  85.             ioextser->IOSer.io_Length  =
  86. buffered>serialbuffersize?serialbuffersize:buffered;
  87.             ioextser->IOSer.io_Data    = (APTR)serialbuffer;
  88.             BeginIO((struct IORequest *)ioextser);
  89.  
  90.             if(!(ioextser->IOSer.io_Flags & IOF_QUICK))
  91.             {
  92.                 bits = Wait(*other_signals | serialmask);
  93.     
  94.                 GetStamp(×tamp);
  95.     
  96.                 if (bits & serialmask)
  97.                 {
  98.                     WaitIO((struct IORequest *)ioextser);
  99.                 }
  100.                 else
  101.                 {
  102.                     AbortIO((struct IORequest *)ioextser);
  103.                     WaitIO((struct IORequest *)ioextser);
  104.                     *other_signals = bits & (~serialmask);
  105.                     return(data_ready);
  106.                 }
  107.             }
  108.  
  109.             for(i=0;i<ioextser->IOSer.io_Actual;i++)
  110.             {
  111.                 pb_byte = serialbuffer[i];
  112.                 (*ProcessByte)();
  113.             }
  114.         }
  115.     }
  116. }
  117.  
  118. ---------------------------------------------------------------------------
  119.  
  120.